package com.sgb.kjwl.view.ui.adapter.lease;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.LayoutLeaseSetBinding;
import com.sgb.kjwl.databinding.LayoutLeaseShowBinding;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.lease.PriceSetEntity;
import com.sgb.kjwl.utils.EditInputFilter;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter2;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MToast;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 价格动态显示适配器
 */
public class PriceShowAdapter extends BaseRecycleAdapter2<PriceSetEntity> {

    private Context context;
    private boolean isDriver = false;//是否显示自带驾驶员价格
    private boolean isTariff = false;//是否含税
    private String categoryType = "0";//0，机械，1 设备

    public void setDriverAndTariff(boolean isDriver, boolean isTariff) {
        this.isDriver = isDriver;
        this.isTariff = isTariff;
    }

    public void setCategoryType(String categoryType) {
        this.categoryType = categoryType;
    }

    public PriceShowAdapter(Context context, List<PriceSetEntity> datas) {
        super(context, R.layout.layout_lease_show, datas);
        this.context = context;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void convert(ItemViewHolder holder, PriceSetEntity priceSetEntity, int position) {
        holder.setBinding(BR.viewModel, priceSetEntity);
        LayoutLeaseShowBinding binding = (LayoutLeaseShowBinding) holder.getmBinding();

        if ("1".equals(categoryType)) {
            binding.itemTvPriceDriver.setLabelName("租赁价格(不含税，含操作员)");
            binding.itemTvPriceDriverNot.setLabelName("租赁价格(不含税，不含操作员)");
        }

        if (priceSetEntity != null) {
            //设置带驾驶员价格
            binding.itemTvPriceDriver.setContent(toDecimalFormat(priceSetEntity.getDriverPrice()));
            binding.itemTvPriceDriver.setLabelRight(priceSetEntity.getPriceUnitName());
            //设置不带驾驶员价格
            binding.itemTvPriceDriverNot.setContent(toDecimalFormat(priceSetEntity.getNoDriverPrice()));
            binding.itemTvPriceDriverNot.setLabelRight(priceSetEntity.getPriceUnitName());
            //设置含税价
            binding.tvPrice1Reate.setText(priceSetEntity.getDriverReatePrice() + priceSetEntity.getPriceUnitName());
            binding.tvPrice2Reate.setText(priceSetEntity.getNoDriverReatePrice() + priceSetEntity.getPriceUnitName());
            //设置是否显示自带驾驶员价格.并隐藏非必填的空数据
            if (TextUtils.isEmpty(priceSetEntity.getDriverPrice())) {
                binding.itemTvPriceDriver.setVisibility(View.GONE);
                binding.rlPrice1Reate.setVisibility(View.GONE);
            } else {
                binding.itemTvPriceDriver.setVisibility(View.VISIBLE);
                binding.rlPrice1Reate.setVisibility(View.VISIBLE);
                binding.rlPrice1Reate.setVisibility(isTariff ? View.VISIBLE : View.GONE);
            }

            if (TextUtils.isEmpty(priceSetEntity.getNoDriverPrice())) {
                binding.itemTvPriceDriverNot.setVisibility(View.GONE);
                binding.rlPrice2Reate.setVisibility(View.GONE);
            } else {
                binding.itemTvPriceDriverNot.setVisibility(View.VISIBLE);
                binding.rlPrice2Reate.setVisibility(View.VISIBLE);
                binding.rlPrice2Reate.setVisibility(isTariff ? View.VISIBLE : View.GONE);
            }
        }

    }

    private String toDecimalFormat(String price) {
        try {
            return new DecimalFormat("0.00").format(Double.parseDouble(price));
        } catch (Exception ex) {
            return price;
        }
    }

}
